package chapter01.d02;

import javax.swing.plaf.SliderUI;

/**
 * 方便共享资源，同一份资源可以有多个代理访问
 * 
 * @author kenneth
 *
 */
public class TicketThread2 implements Runnable {
	private int ticket = 10;

	@Override
	public void run() {
		for (int i = 0; i < 1000; i++) {

			synchronized (this) {
				if (ticket > 0) {
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					
					System.out.println(Thread.currentThread().getName() + "\t抢到：" + ticket-- +"号票");
				}

			}
		}
	}
}
